<template>
	<view>
		<!--pages/mycard/mycard.wxml-->
		<view class="viewa">共有<text>{{cards.length}}</text>个礼品卡</view>
		<block v-for="(item, index) in cards" :key="index">
			<view class="viewb">
				<image src="/static/images/gift_bg.png"></image>
				<view class="viewbInner">
					<view class="use_gift">
						<view class="gift_type">【礼品卡】</view>
						<view class="viewbInner1">{{item.title}}</view>
						<view class="viewbInner2">截止：{{item.end_time}}</view>
					</view>
					<view v-if="item.status!=1" class="go_use" @tap="card" :data-id="item.id">
						<text class="use not-use" v-if="item.use">已过期</text>
						<text class="use" v-else>去使用</text>
					</view>
					<view v-else class="go_use">
						<text class="use not-use">已使用</text>
					</view>
				</view>
			</view>
		</block>
	</view>
</template>

<script>
	// pages/mycard/mycard.js
	const app = getApp().globalData;

	export default {
		data() {
			return {
				cards: []
			};
		},

		components: {},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
			// #ifdef MP-ALIPAY
			if (JSON.stringify(options) == '{}') {
				options = my.getLaunchOptionsSync().query;
			}
			// #endif
			if (options && (options.store_id || options.storeid)) {
				this.$store.store_id = options.store_id ? options.store_id : options.storeid;
			}
		},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: async function() {
			await this.$onLaunched;
			var that = this;
			getApp().globalData.sendRequest({
				url: '/GiftCard/getMyCard',
				type: "post",
				data: {},
				success: function(re) {
					// console.log(re);
					if (re.status == 1) {
						that.setData({
							cards: re.gift_order
						});
					}
				}
			});
		},
		
		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage(res) {
			return {
				title: '我的礼品卡',
				path: '/pages/mine/gift_mycard/gift_mycard?store_id=' + this.$store.store_id +
					'&share_uid=' + app.XcxData.userInfo.uid,
				success: function(res) { // 转发成功
				},
				fail: function(res) { // 转发失败
				}
			};
		},
		methods: {
			card: function(e) {
				uni.navigateTo({
					url: '../gift_card/gift_card?id=' + e.currentTarget.dataset.id
				});
			}
		}
	};
</script>
<style>
	@import "./gift_mycard.css";
</style>
